#import "YYText.h"
#import "dfhgwhruebvhrheyadmitultimate.h"
#import "dfhgwhruebvhrheystallsecurity.h"
#import "dfhgwhruebvhrheygarbageequator.h"
#import "dfhgwhruebvhrheycalmprophet.h"
#import "dfhgwhruebvhrheyminimalfantasyViewController.h"
@interface dfhgwhruebvhrheycalmprophet ()
@property (nonatomic, strong) dfhgwhruebvhrheystallsecurity *couponView;
@property (weak, nonatomic) IBOutlet UIView *topView;
@property (weak, nonatomic) IBOutlet UIView *planView;
@property (weak, nonatomic) IBOutlet UIView *overdueView;
@property (weak, nonatomic) IBOutlet YYLabel *overdueLabel;
@property (weak, nonatomic) IBOutlet UILabel *tipsTextLabel;
@property (weak, nonatomic) IBOutlet UIView *couponViewContainer;
@property (weak, nonatomic) IBOutlet UILabel *repaymentDateTextLabel;
@property (weak, nonatomic) IBOutlet UILabel *repaymentAmountTextLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *planViewHeightConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *overdueViewHeightConstraint;
@end
@implementation dfhgwhruebvhrheycalmprophet {
    void(^_callback)(int type);
}
- (dfhgwhruebvhrheystallsecurity *)couponView {
	if (_couponView == nil) {
		_couponView = [[NSBundle mainBundle] loadNibNamed:@"dfhgwhruebvhrheystallsecurity" owner:nil options:nil].firstObject;
        _couponView.radius = 8;
        _couponView.coupon = nil;
        _couponView.cornerRadius = 10;
        _couponView.vlineToTopHeight = 60;
		_couponView.backgroundColor = [UIColor whiteColor];
	}
	return _couponView;
}
- (void)awakeFromNib {
	[super awakeFromNib];
    self.topView.backgroundColor = [UIColor clearColor];
	self.couponView.money = @"2000";
	[self.couponView drawArcAndLine:nil];
	[self.couponViewContainer addSubview:self.couponView];
	__weak typeof(self) weakSelf = self;
	[self.couponView couponClick:^(dfhgwhruebvhrheystallsecurity * _Nonnull couponView) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		dfhgwhruebvhrheyminimalfantasyViewController *list = (dfhgwhruebvhrheyminimalfantasyViewController *)[UIStoryboard storyboard:@"Home" withidentifier:@"coupon_list"];
        list.isRepayment = YES;
        list.hidesBottomBarWhenPushed = YES;
		[strongSelf.controller.navigationController pushViewController:list animated:YES];
	}];
}
- (void)bindOverDayData:(dfhgwhruebvhrheyadmitultimate *)model {
	NSMutableAttributedString *tipsAttribute = [[NSMutableAttributedString alloc] initWithString:@"As long as you keep a good repayment record, you will enjoy the audit exemption period when you re-loan. you can re-loan immediately after paid your fully amount. If the payment is overdue for several days, your next loan amount may decreased. The system will gradually increase your loan limit for you again."];
	NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
	style.lineSpacing = 5;
	[tipsAttribute addAttributes:@{
		NSParagraphStyleAttributeName: style,
		NSFontAttributeName: [UIFont regular:13],
		NSForegroundColorAttributeName: @"#AAAAAA".dhgfywegwygeydwlearneddesignate
	} range:NSMakeRange(0, tipsAttribute.length)];
	self.tipsTextLabel.numberOfLines = 0;
	self.tipsTextLabel.attributedText = tipsAttribute;
	if (model.due_days == 0) {
		self.overdueView.hidden = YES;
		self.overdueViewHeightConstraint.constant = 0;
	}else {
		self.overdueView.hidden = NO;
		self.overdueViewHeightConstraint.constant = 32;
		NSString *overdueString = [NSString stringWithFormat:@"You have been overdue %d days", model.due_days];
		NSMutableAttributedString *overAttribute = [[NSMutableAttributedString alloc] initWithString:overdueString];
		NSRange range = [overdueString rangeOfString:[NSString stringWithFormat:@"%d", model.due_days]];
		[overAttribute addAttributes:@{NSForegroundColorAttributeName:@"#3B414B".dhgfywegwygeydwlearneddesignate, NSFontAttributeName:[UIFont regular:13]} range:NSMakeRange(0, overdueString.length)];
		[overAttribute addAttributes:@{NSForegroundColorAttributeName: @"#FB3314".dhgfywegwygeydwlearneddesignate} range:range];
		self.overdueLabel.attributedText = overAttribute;
	}
}
- (void)bindRepayment:(dfhgwhruebvhrheygarbageequator *)model {
	NSString *money = model.is_ins_repay == 1 ? [NSString stringWithFormat:@"%d", model.current_amount] : [NSString stringWithFormat:@"%d", model.final_amount];
	self.repaymentAmountTextLabel.text = [NSString stringWithFormat:@"PHP %@", money.dhgfywegwygeydwlocalitylearned];
}
- (void)setShowRepayPlan:(BOOL)showRepayPlan {
	if (showRepayPlan) {
		self.planView.hidden = NO;
		self.planViewHeightConstraint.constant = 52;
	}else {
		self.planView.hidden = YES;
		self.planViewHeightConstraint.constant = 0;
	}
}
- (IBAction)repayAction:(UIButton *)sender {
	if (![dfhgwhruebvhrheyoptionsaving isLogin]) {
		[dfhgwhruebvhrheyoptionsaving login:nil];
	}else {
		NSLog(@"去还款");
		if (_callback) {
			_callback(2);
		}
	}
}
- (void)showRepayPlanCallBack:(void(^)(int type))callback {
	_callback = callback;
}
- (IBAction)showRepayPlanView:(UITapGestureRecognizer *)sender {
	if (_callback) {
		_callback(1);
	}
}
- (void)layoutSubviews {
	[super layoutSubviews];
	[self.couponView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.edges.equalTo(self.couponViewContainer);
	}];
}
@end
